<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<title></title>
		<!--<link rel="stylesheet" href="../css/common.css" />-->
		<link rel="stylesheet" href="../css/mui.min.css" />
		<script type="text/javascript" src="../js/template-web.js" ></script>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../js/mobile-detect.min.js" ></script>
		<script type="text/javascript" src="../js/config.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../controll/index.js"></script>
	</head>
	<style>
		html,
		body {
			position: relative;
			height: 100%;
		}
		.hidden{
			/*display: none;*/
		}
		#div1 {
			height: 90px;
			background-color: dodgerblue;
		}
		
		#div1 input {
			display: inline-block;
			width: 70%;
			height: 50px;
		}
		
		#div1 button {
			display: inline-block;
			width: 25%;
			height: 50px;
		}
		
		#div2 {
			width: 92%;
			margin: 0 4%;
			height: 45px;
			padding-left: 15px;
			border: 0;
			border-radius: 10px;
			color: #666;
		}
		ul, li, ol{
			text-align: center;
			list-style: none;
			padding: 0;
			margin: 0;
		}
		.jp{
			background: #fff;
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			font-size: 0;
		}
		.jp ul li{
			width: 33.333%;
			height: 50px;
			font-size: 16px;
			display: inline-block;
			font-weight: 900;
			line-height: 50px;
			border: 1px solid #E9E9E9;
		}
		.proItem {
			background: #FFF;
			position: relative;
			padding: 5px 15px 5px 15px;
			margin: 15px;
			border-radius: 10px;
		}
		.proItem span{
			width: 50px;
			font-size: 30px;
			line-height: 90px;
			position: absolute;
			left: 15px;
			color: #999;
			top: 0;
		}
		.proItem input{
			line-height: 50px;
			width: 100%;
			border: 0;
			font-size: 30px;
			color: #FF4400;
			text-align: center;
			margin: 0;
			height: 60px;
		}
		.footer{
			width: 100%;
			padding: 15px;
		}
		.footer button{
			background: #1E90FF;
			width: 46%;
			border-radius: 8px;
			border: 0;
		}
		.footer button img{
			height: 26px;
			margin-top: 5px;
		}
		.footer button span{
			position: relative;
			top: -8px;
			left: 3px;
			color: #fff;
		}
		.pay-btn-way-img{
			width: 30px;
			height:30px;
		}
		.top-btn-border{
			display: flex;justify-content: space-between;width:100%;margin-bottom:15px;
		}
		.left-btn{
			padding-right:7.5px;box-sizing: border-box;width: 50%;float:left;
		}
		.btn-left-apliay{
			width: 100%;background: #56ABE4;
		}
		.right-btn{
			padding-left:7.5px;box-sizing: border-box;float:left;width:50%;
		}
		.btn-left-weixin{
			width:100%;background: #4CB853;
		}
		.no-magin{
			margin-bottom:0px;
		}
		.top-btn-border button{
			width:100%;
			border-radius:30px;
			font-size:15px;
		}
		.top-btn-border button.bg-blue-btn,.bg-shenblue-btn{
			background: #56ABE4;
		}
		.top-btn-border button.bg-green-btn{
			background: #4CB853;
		}
		.top-btn-border button.bg-shenblue-btn{
			background: #2F81D2;
		}
		.big-btn{
			width:100%;
			border-radius:30px;
			
		}
	</style>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" style="margin: 0 50px;">普通收款</h1>
			<span class="mui-pull-right" style="height: 100%; line-height: 44px;opacity: 999;">押金收款</span>
		</header>
		<div class="mui-content">
			<div class="proItem">
				<span>￥</span>
				<input readonly type="text" id="sum" placeholder="0.00" value="" maxlength="8" />
			</div>
			<input type="text" id="div2" name="" placeholder="备注信息："></input>
			<div class="jp">
				<ul>
					<li class="num">1</li>
					<li class="num">2</li>
					<li class="num">3</li>
					<li class="num">4</li>
					<li class="num">5</li>
					<li class="num">6</li>
					<li class="num">7</li>
					<li class="num">8</li>
					<li class="num">9</li>
					<li class="num">.</li>
					<li class="num">0</li>
					<li class="del">
						<img src="../img/ic_delete@2x.png" />
					</li> 
				</ul>
			</div>
			<div class="footer">
				<script type="text/template" id="diposit0">
					<div class="top-btn-border" >
						<!--<div class="left-btn">
						<button type="button" class="mui-btn face_pay btn-left-apliay bg-blue-btn" >
							<img src="../img/ic_alipay.png" class="pay-btn-way-img" />
							<span>支付宝扫脸支付</span>
						</button>
						</div>
						<div class="right-btn" >
						<button type="button" class="mui-btn weixin_face_pay btn-left-weixin bg-green-btn">
							<img src="../img/ic_wechat.png" class="pay-btn-way-img" />
							<span>微信扫脸支付</span>
						</button>
						</div>-->
					</div>
					
					{{if status =='p1'}}
					<div class="top-btn-border no-magin" >
						<div class="left-btn">
						<button type="button" class="mui-btn backCardPay btn-left-apliay bg-shenblue-btn" >
							<img src="../img/ic_deposit_unionpay.png" class="pay-btn-way-img"/>
							<span>银行卡收款</span>
						</button>
						</div>	
						<div class="right-btn" >
						<button type="button" class="mui-btn pay_scan btn-left-apliay bg-shenblue-btn">
							<img src="../img/ic_deposit_scan_white.png" class="pay-btn-way-img" />
							<span>扫码收款</span>
						</button>
						</div>
					</div>
					
					{{else}}
					<div class="top-btn-border no-magin" >
					<button type="button" class="mui-btn pay_scan bg-shenblue-btn big-btn">
						<img src="../img/ic_deposit_scan_white.png" class="pay-btn-way-img" />
						<span>扫码收款</span>
					</button>
					</div>
					
				
					{{/if}}
					
				</script>
			</div>
		</div>
		
		<script type="text/javascript">
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			mui.plusReady(function() {
				var yunSuan = 0; //运算符号，0-无运算;1-加法;2-减法;3-乘法;4-除法
				var change = 0; //属于运算符后需要清空上一数值
				var num1 = 0; //运算第一个数据
				var num2 = 0; //运算第二个数据
				var exp = /^(([1-9][0-9]*)|(([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2})))$/;
				var cunChuValue = 0; //存储的数值
				
				var temData = {
					status: "v1"
				};
				$('body').height($(window).height());
				if(getSysInfo().search("P1")!= -1) {
					temData = {
						status: "p1"
					};
				}
				
				var winHeight = $(window).height();   //获取当前页面高度
				$(window).resize(function(){
				   var thisHeight=$(this).height();
				    if(winHeight - thisHeight >50){
				         //当软键盘弹出，在这里面操作
						$(".jp").addClass("hidden");
				    }else{
				        //当软键盘收起，在此处操作
						$(".jp").removeClass("hidden");
				    }
				});
				
				//渲染
				var str1 = template("diposit0", temData);
				$(".footer").append(str1);
				
				$("#sum").focus(function(){
			        document.activeElement.blur();
			        $(".jp").removeClass("hidden");
			    });
			    
			    //备注栏获得焦点
			    $("#div2").focus(function(){
			    	$(".jp").addClass("hidden");
			    })
			    
			    $(".num").click(function(){
			    	var val=$("#sum").val();
			    	var valOfter=val+""+$(this).html();
			    	if(valOfter.length > 8){
			    		return false;
			    	}
			    	if(exp.test(valOfter + "") || valOfter === "0"){
			    		$("#sum").val(valOfter);
			    	}
			    })
			    //点击后退按钮
			    $(".del").click(function(){
			    	var value=$("#sum").val();
			    	value = value.substr(0, value.length - 1);
					$("#sum").val(value);
			    })
			    
			    var timeSign = false;
			    //点击扫码收款或银行卡收款
			    mui("body").on("tap",".backCardPay, .pay_scan, .face_pay, .weixin_face_pay",function(){
			    	
			    	var price=$("#sum").val();
			    	if(price*1>0){
//			    		$(".jp").addClass("hidden");
			    	}else{
			    		mui.alert("收款金额不合法", " ", "关闭", function() {}, "div");
			    		return false;
			    	}
			    	if (!timeSign) {
			    		timeSign = true
			    	} else {
			    		return;
			    	}
			    	setTimeout(function () {
			    		timeSign = false;
			    	},3000);
			    	if($(this).hasClass("pay_scan")){
			    		//扫码收款
			    		mui.openWindow({
							url: "./public/barcode_scan.html",
							id: "barcode_scan.html",
							extras: {
								price: Number(price),
								remark:$("#div2").val()
							}
						});
						return false;
			    	};
			    	if ($(this).hasClass("face_pay")) {
			    		// 扫脸支付
			    		plus.nativeUI.showWaiting("正在处理中，请稍候");
			    		require(weburl + facePay, "json", "post", {
			    			token: localStorage.getItem("token"),
			    			payways: "alipay",
			    			pay_type: "pay",
			    			amount: price + "",
			    			remark: $('#div2').val()
			    		}, function(response){
			    			console.log(JSON.stringify(response));
			    			plus.nativeUI.closeWaiting();
			    			if(response.status == "success") {
								$(".pay_remarks").val("");
								$(".price-cash").val("0.00");
								printTicket(response.data[0].print_array);
								mui.confirm("收款成功，是否打印小票？", " ", ["打印", "关闭"], function(e) {
									if(e.index == 0) {
										printTicket(response.data[0].print_array);
										return false;
									} else {
										mui.openWindow({ 
											url: "detail.html",
											id: "detail",
											extras: {
												orderNum: response.data[0].out_trade_no
											}
										})
									}
								}, "div");
			    			} else {
			    				mui.alert(response.msg, "", "关闭", function(){}, "div");
			    			}
			    		}, function(err){
			    			plus.nativeUI.closeWaiting();
			    			mui.alert("支付超时，请稍后再试", "", "关闭", function(){}, "div");
			    			console.log(err);
			    		})
			    		return false;
			    	};
						if ($(this).hasClass("weixin_face_pay")) {
							// 扫脸支付
							plus.nativeUI.showWaiting("正在处理中，请稍候");
							require(weburl + facePay, "json", "post", {
								token: localStorage.getItem("token"),
								payways: "weixin",
								pay_type: "pay",
								amount: price + "",
								remark: $('#div2').val()
							}, function(response){
								console.log(JSON.stringify(response));
								plus.nativeUI.closeWaiting();
								if(response.status == "success") {
								$(".pay_remarks").val("");
								$(".price-cash").val("0.00");
								printTicket(response.data[0].print_array);
								mui.confirm("收款成功，是否打印小票？", " ", ["打印", "关闭"], function(e) {
									if(e.index == 0) {
										printTicket(response.data[0].print_array);
										return false;
									} else {
										mui.openWindow({ 
											url: "detail.html",
											id: "detail",
											extras: {
												orderNum: response.data[0].out_trade_no
											}
										})
									}
								}, "div");
								} else {
									mui.alert(response.msg, "", "关闭", function(){}, "div");
								}
							}, function(err){
								plus.nativeUI.closeWaiting();
								mui.alert("支付超时，请稍后再试", "", "关闭", function(){}, "div");
								console.log(err);
							})
							return false;
						};
			    	//银行卡普通收款
			    	require(weburl + BankOrderCreate, "json", "post", {
						token: localStorage.getItem("token"),
						amount: price+"",
						pay_type: "pay",
						remark: $('#div2').val()
					}, function(response) {
						console.log(JSON.stringify(response));
						plus.nativeUI.closeWaiting();
						if(response.status == "success") {
							var main = plus.android.runtimeMainActivity();
							var data = {
								token: localStorage.getItem("token"),
								amount: response.data[0].amount,
								barcodeType: 0+"",
								orderInfo: $("#div2").val() ? $("#div2").val() : "",
								orderNoSFT: response.data[0].out_trade_no,
								payCallUrl: weburl + "/api/",
								remark: response.data[0].remark?response.data[0].remark:''
							}
							main.BankCarTrade("1", JSON.stringify(data));
							return false;
						}
						mui.alert(response.msg, " ", "关闭", function() {}, "div");
					}, function(xhr) {
						plus.nativeUI.closeWaiting();
						mui.alert("创建订单失败，请稍后重试！", " ", "关闭", function() {}, "div");
					})
			    	
			    })
			    
//				mui("body").on("tap", ".tijiao", function() {
//					$(".jp").addClass("hidden");
//					var price = $('#sum').val(); 
//					//判断金额是不是合法数字
//					console.log(price * 1)
//
//					if(!exp.test(price)) {
//						mui.alert("收款金额不合法", " ", "关闭", function() {}, "div");
//						return false;
//					}
//					//如果金额为0
//					if(!(price * 1 > 0)) {
//						mui.alert("收款金额不能为0", " ", "关闭", function() {}, "div");
//						return false;
//					}
//
//					plus.nativeUI.showWaiting('收款金额为：' + Number($('#sum').val()).toFixed(2) + "元");
//
//					setTimeout(function() {
//						var price_n = $('#sum').val();
//						$('#sum').val("");
//						
//						plus.nativeUI.closeWaiting();
//						mui.openWindow({
//							url: "../view/public/barcode_scan.html",
//							id: "barcode_scan.html",
//							extras: {
//								price: Number(price_n),
//								remark:$("#div2").val()
//							}
//						});
//						$("#div2").val("");
//					}, 1000)
//				})
				//点击押金收款,判断是否已经签约
				mui("body").on("tap", ".mui-pull-right", function() {
//					$(".jp").addClass("hidden");
					mui.openWindow("../view/deposit.html", "deposit.html");
				})

//				$(".number").click(function() { //点击数字触发事件
//					$("input[type='text']").blur();
//					var num = $(this).attr('name');
//					var oldValue = $("#sum").val();
//					if(change == 1) {
//						oldValue = "0";
//						change = 0;
//					}
//					var newValue = "";
//					if(num == -1) {
//						oldValue = parseFloat(oldValue);
//						newValue = oldValue * -1;
//					} else if(num == ".") {
//						console.log(oldValue);
//						if(oldValue.indexOf('.') == -1)
//							newValue = oldValue + ".";
//						else
//							newValue = oldValue;
//						console.log(oldValue);
//					} else {
//						if(oldValue == 0 && oldValue.indexOf('.') == -1) {
//							newValue = num;
//						} else {
//							newValue = oldValue + num;
//						}
//					}
//					$("#sum").val(newValue);
//				});
//				$("#qingPing").click(function() { //点击清屏触发事件
//					$("input[type='text']").blur();
//					$("#sum").val("0");
//					yunSuan = 0;
//					change = 0;
//					num1 = 0;
//					num2 = 0;
//				});
//				$("#tuiGe").click(function() { //点击退格触发事件
//					$("input[type='text']").blur();
//					if(change == 1) {
//						yunSuan = 0;
//						change = 0;
//					}
//					var value = $("#sum").val();
//					if(value.length == 1) {
//						$("#sum").val("0");
//					} else {
//						value = value.substr(0, value.length - 1);
//						$("#sum").val(value);
//					}
//				});
//				$(".yunSuan").click(function() { //点击运算符号触发事件
//					$("input[type='text']").blur();
//					change = 1;
//					yuSuan = $(this).attr('name');
//					var value = $("#sum").val();
//					var dianIndex = value.indexOf(".");
//					if(dianIndex == value.length) {
//						value = value.substr(0, value.length - 1);
//					}
//					num1 = parseFloat(value);
//				});
//				$("#dengYu").click(function() { //点击等于符号触发事件
//					$("input[type='text']").blur();
//					var value = $("#sum").val();
//					var dianIndex = value.indexOf(".");
//					if(dianIndex == value.length) {
//						value = value.substr(0, value.length - 1);
//					}
//					num2 = parseFloat(value);
//					var sum = 0;
//					if(yuSuan == 1) {
//						sum = num1 + num2;
//					} else if(yuSuan == 2) {
//						sum = num1 - num2;
//					} else if(yuSuan == 3) {
//						sum = num1 * num2;
//					} else if(yuSuan == 4) {
//						sum = num1 / num2;
//					} else if(yuSuan == 0 || num1 == 0 || num2 == 0) {
//						sum = num1 + num2;
//					}
//					var re = /^[0-9]+.?[0-9]*$/;
//					//					var re=/^\d+(\.\d{1,2})?$/;
//					if(re.test(sum)) {
//						sum = sum.toFixed(2);
//					}
//					$("#sum").val(sum);
//					change = 1;
//					yuSuan = 0;
//					num1 = 0;
//					num2 = 0;
//				});
			})
		</script>
	</body>

</html>